﻿// This is already an implicit subclass of the container...you don't usually see them make a class here.

import com.translator.comms.CommEventStateChange;
import com.translator.comms.IComm;
import com.translator.comms.CommFactory;
import com.translator.comms.ICommState;
import com.widget.HpWidget;
import com.widget.ModeChangeButton;
import flash.text.TextField;
import flash.external.ExternalInterface;
import mx.containers.HBox;
import mx.containers.VBox;
import mx.controls.HRule;
import mx.controls.VRule;
import mx.core.Container;


import flash.display.Sprite;

/**
 * Communication layer we'll be using to store state and such things
 */
private var mComms:IComm;

/**
 * Startup function.  Called when the SWF loads.
 */
public function Startup():void
{
    CommFactory.MakeComm(this, _CommsReady);
}

/**
 * Called when the Comm is ready to go
 */
private function _CommsReady(comms:IComm):void
{
    mComms = comms;

    var SIZE_X:Number = 2;
    var SIZE_Y:Number = 1;


    var hLayout:Container = new HBox();
    hLayout.percentWidth = 100;
    hLayout.percentHeight = 100;

    for (var i:Number = 0 ; i < SIZE_X ; ++i)
    {
        var vLayout:Container = new VBox();
        vLayout.percentWidth = 100;
        vLayout.percentHeight = 100;
        for (var j:Number = 0 ; j < SIZE_Y ; ++j)
        {
            var hpWidget:HpWidget = new HpWidget(mComms);
            hpWidget.percentWidth = 100;
            hpWidget.percentHeight = 100;
            vLayout.addChild(hpWidget);
            if (j + 1 != SIZE_Y)
            {
                var hRuler:HRule = new HRule();
                hRuler.percentWidth = 100;
                vLayout.addChild(hRuler);
            }
        }
        hLayout.addChild(vLayout);
        if (i + 1 != SIZE_X)
        {
            var vRuler:VRule = new VRule();
            vRuler.percentHeight = 100;
            hLayout.addChild(vRuler);
        }
    }
    addChild(hLayout);

    // Allow us to change modes
    var modeChangeButton:ModeChangeButton = new ModeChangeButton(mComms);
    modeChangeButton.x = 690;
    modeChangeButton.y = 0;
    addChild(modeChangeButton);
}